<?php
include_once('./base/conn.php');
include_once('./base/wxCofig.php');
include_once('./wxphp/xcx.class.php');
include_once('./base/xcx_commonclass.php');
include_once('./base/xcx_sqlclass.php');
$code          = $_POST['code'];
$iv            = $_POST['iv'];
$encryptedData = $_POST['encryptedData'];
$appid=$appid;
$appkey=$appkey;


$mysql=new MMsql();
$getOpenId=new xcxfunService();
//[session_key: "dQkP5Cnh5zvAC0nepipbvg==", openid: "o5ql45DvF2DQ_-_HtQLq5j13n6Hw"]
$rs=$getOpenId->fnGetopenInfo($appid,$appkey,$code,$iv,$encryptedData);
    $openId=$rs['openId'];
    $nickName=$rs['nickName'];
    $gender=$rs['gender'];
    $country=$rs['country'];
    $province=$rs['province'];
    $city=$rs['city'];
    $avatarurl=$rs['avatarUrl'];
$sql="select * from wk_userinfo where openid='".$openId."'";
$result=$mysql->doSql($sql);
if(count($result)==0) {
		 $fun=new commonfun();
		 $userid=$fun->creatId('user_id');
    	 $sql2="insert into wk_userinfo(userid,openid,nickname,avatarurl,gender,country,province,city)
    	 VALUES ('".$userid."','".$openId."','".$nickName."','".$avatarurl."','".$gender."',
    	 '".$country."','".$province."','".$city."')";
		 $result=$mysql->doSql($sql2);
	}else{
		
  	     $sql3="update wk_userinfo set openid='".$openId."',nickname='".$nickName."',
  	     avatarurl='".$avatarurl."',province='".$province."',gender='".$gender."',country='".$country."'
  	     ,city='".$city."'   where openid='".$openId."'";
  	      $result=$mysql->doSql($sql3);
  }
  
  $list=$mysql->doSql($sql);
	
echo json_encode($list);
//echo "998";

?>